package weeny.demo;

import java.awt.geom.Line2D;
import java.awt.geom.Point2D;

import javax.swing.JFrame;

import prefuse.util.FontLib;
import prefuse.util.ui.UILib;
import prefuse.visual.VisualItem;

import weeny.face.LoadSaveBox;
import weeny.face.WidgetTabbedPane;
import weeny.pre.display.BaseUIDisplay;
import weeny.pre.display.MoreVisualization;
import weeny.pre.util.IntColor;
import weeny.pre.util.Marker;
import weeny.pre.util.Pre;

import static weeny.pre.display.BaseUIDisplay.IO_DISPLAY_TAB;

/**
 * Example of using multiple markers
 * 
 * @author weeny
 */
public class BaseUIDisplayDemo{
	
	public static void main(String[] args) {
		UILib.setPlatformLookAndFeel();
		MoreVisualization vis = new MoreVisualization();
		BaseUIDisplay display = new BaseUIDisplay(vis);
		//turn on all display control, such as zoom, pan, etc.
		display.setAllControl(true);
		
		
		WidgetTabbedPane markserTabs = new WidgetTabbedPane();		
		
		
		Marker m1 = vis.addMarker("Marker 1");
		Marker m2 = vis.addMarker("Marker 2");
		//create a loadsavebox with the option to set default file name
		LoadSaveBox lsBox = m1.createLoadSaveBox("file.xml");
		
		markserTabs.addWidget(m1.getGroup(), LoadSaveBox.withInputField(lsBox));
		markserTabs.addWidget(m1.getGroup(), m1.createShowDummyCheck());
		markserTabs.addWidget(m1.getGroup(), m1.createRendererControl());
		
		markserTabs.addWidget(m2.getGroup(), m2.createLoadSaveBox(null));
		markserTabs.addWidget(m2.getGroup(), m2.createShowDummyCheck());
		markserTabs.addWidget(m2.getGroup(), m2.createRendererControl());
		
		display.addWidget(IO_DISPLAY_TAB, markserTabs);
		
		
		Point2D p1 = new Point2D.Double(200, 100);
		Point2D p2 = new Point2D.Double(400,10);
		Point2D p3 = new Point2D.Double(10, 400);
		
		//draw something in marker1
		VisualItem vi = m1.drawText(p1, m1.getGroup(), 10);
		vi.setTextColor(IntColor.ORIANGE);
		m1.drawArrow(p1, 100, Math.PI/2, IntColor.GREEN);
		m1.drawPolyline(
				new float[]{500,510,200,400,100,200,30,400}, IntColor.RED, 10);		
		
		//draw something in marker2
		vi = m2.drawLine(p2, p3, IntColor.ORIANGE, 10);
		vi.setStroke(Pre.roundStroke(10));
		vi = m2.drawText(new Point2D.Double(350, 590), m2.getGroup(), 10);
		vi.setFont(FontLib.getFont("Georgia", 10));

		vi.setTextColor(IntColor.PINK);
		m2.drawLine(new Line2D.Double(400,100,229,400), IntColor.GREEN, 10);
		m2.drawCurve(new float[]{593,163,123,523,146,64}, IntColor.BLUE, 15);

		//configure interface
		display.setSize(800, 600);
		display.showIODisplayTab();
		display.showItemControlTabInTree();
		JFrame frame = display.frameView("Multiple Markers Demo");
		frame.pack();
		frame.setVisible(true);
	}
}